
function getTree(arr, item, key){
  item.children = item.children ? item.children : []
  arr.forEach(obj => {
    if(obj.parentId === key){
      item.children.push(obj)
      getTree(arr, obj, obj.key)
    }else{
      return
    }
  })
  return item.children
}

export function ArrayToTree(arr) {
  let newArr = []
  arr.forEach(item => {
    if(!item.parentId){
      newArr.push(item)
      getTree(arr, item, item.key)
    }
  })
  return newArr
}

/** 移动 */
export const move = (arr, index1, index2) => {
   arr[index1] = arr.splice(index2, 1 , arr[index1])[0]
   return arr
}
